package com.it.sun.yuebike.framework.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName com.it.sun.yuebike.framework.config.MvcConfig
 * @Author sunmannian
 * @Date 2021/5/31 11:24
 * @Version V1.0
 * Description  <mvc 配置>
 * Copyright (C) 北京中电兴发科技有限公司  since 2021/5/31
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");

    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/swagger", "/swagger-ui.html")
                .setStatusCode(HttpStatus.PERMANENT_REDIRECT);
        registry.addRedirectViewController("/doc", "/doc.html")
                .setStatusCode(HttpStatus.PERMANENT_REDIRECT);
    }
}



